package com.hjm.project.merchantInfo.merSyncRecord.controller;

import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.common.utils.request.AutoLoadData;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.framework.web.page.TableDataInfo;
import com.hjm.project.merchantInfo.merSyncRecord.domain.MerSyncRecord;
import com.hjm.project.merchantInfo.merSyncRecord.service.IMerSyncRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@Controller
@RequestMapping("/merSyncRecord/merSyncRecord")
public class MerSyncRecordController extends BaseController {
    private String prefix = "merchantInfo/merSyncRecord";

    @Resource
    private IMerSyncRecordService merSyncRecordService;

    @RequiresPermissions("merSyncRecord:merSyncRecord:view")
    @GetMapping()
    public String merSyncRecord() {
        return prefix + "/merSyncRecord";
    }

    @RequiresPermissions("merSyncRecord:merSyncRecord:view")
    @GetMapping("/merSyncRecord")
    public String merSyncRecordAgent() {
        return prefix + "/merSyncRecordAgent";
    }

    @RequiresPermissions("merSyncRecord:merSyncRecord:view")
    @GetMapping("/merSyncRecordUpdate")
    public String merSyncRecordUpdate() {
        return prefix + "/merSyncRecordUpdate";
    }

    /**
     * 查询商户信息同步记录列表
     *
     * @param merSyncRecord
     * @return
     */
    @RequiresPermissions("merSyncRecord:merSyncRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MerSyncRecord merSyncRecord) {
        startPage();
        List<MerSyncRecord> list = merSyncRecordService.selectMerSyncRecordList(merSyncRecord);
        for (MerSyncRecord syncRecord : list) {
            syncRecord.setBackIdImg(AutoLoadData.imgurl+syncRecord.getBackIdImg());
            syncRecord.setFontIdImg(AutoLoadData.imgurl+syncRecord.getFontIdImg());
            syncRecord.setBankcardImg(AutoLoadData.imgurl+syncRecord.getBankcardImg());
        }
        return getDataTable(list);
    }

    /**
     * 导出商户信息同步记录列表
     */
    @RequiresPermissions("merSyncRecord:merSyncRecord:export")
    @Log(title = "商户信息同步", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MerSyncRecord merSyncRecord) {
        List<MerSyncRecord> list = merSyncRecordService.selectMerSyncRecordList(merSyncRecord);
        ExcelUtil<MerSyncRecord> util = new ExcelUtil<MerSyncRecord>(MerSyncRecord.class);
        return util.exportExcel(list, "merSyncRecord");
    }

    /**
     * 新增商户信息同步记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存商户换机,商户迁移
     */
    @RequiresPermissions("merSyncRecord:merSyncRecord:add")
    @Log(title = "商户信息同步", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MerSyncRecord merSyncRecord) {
        return toAjax(merSyncRecordService.insertMerSyncRecord(merSyncRecord));
    }

    /**
     * 修改商户信息同步记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        MerSyncRecord merSyncRecord = merSyncRecordService.selectMerSyncRecordById(id);
        mmap.put("merSyncRecord", merSyncRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存商户信息同步记录
     */
    @RequiresPermissions("merSyncRecord:merSyncRecord:edit")
    @Log(title = "商户信息同步", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MerSyncRecord merSyncRecord) {
        return toAjax(merSyncRecordService.updateMerSyncRecord(merSyncRecord));
    }

    /**
     * 删除商户信息同步记录
     */
    @RequiresPermissions("merSyncRecord:merSyncRecord:remove")
    @Log(title = "商户信息同步", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(merSyncRecordService.deleteMerSyncRecordByIds(ids));
    }
}
